import { PixelFile } from "../../../components/canvas/Data/CanvasFile";
import { ProPixelFile } from "./ProPixelFile";
import { randomUUID } from "../createUUID";
import { preview } from "../local";

export class ProPixelPreview implements Omit<PixelFile, "layers"> {
    id: string = randomUUID();
    user: string = "unknown";
    name: string = "undefined";
    height: number = 64;
    width: number = 64;
    version: string = "1.0.0";
    createdAt: number = new Date().getTime();
    updatedAt: number = new Date().getTime();
    constructor(input: Partial<ProPixelPreview> | ProPixelFile | null) {
        if (input === null) console.error("读取 preview 出现空值");
        Object.assign(this, input);
    }
    image?: string;
    save() {
        const data = JSON.parse(JSON.stringify(this));
        return preview.setItem(this.id, data);
    }
}
